from io import StringIO
from contextlib import redirect_stdout

code = '''
import pandas as pd
import numpy as np
s = pd.Series([1, 3, 5, np.nan, 6, 8])
print(s)
'''

f = StringIO()
with redirect_stdout(f):
    exec(code, dict())

s = f.getvalue()
print(s)
